/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aybolit.core.objects.dao.impl;

import aybolit.core.objects.dao.PacientDao;
import aybolit.core.objects.model.Operators;
import aybolit.core.objects.model.Patientes;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Masumov Emin
 */
@Transactional
public class PacientDaoImpl extends DAO implements PacientDao, Serializable {

    SessionFactory sessionFactory;

    @Override
    public void addPacient(Patientes patientes) {
       sessionFactory.getCurrentSession().save(patientes);
    }

    @Override
    public List<Patientes> findAllpacient() {
       return sessionFactory.getCurrentSession().getNamedQuery("Patientes.findAllPatientes").list();     
    }

    @Resource(name = "sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public Patientes findPacient(String id) {
          Patientes p=(Patientes)sessionFactory.getCurrentSession().getNamedQuery("Patientes.findPatientById").setParameter("id", Integer.parseInt(id)).uniqueResult();
          return p;
    }
    
    @Override
    public List<Operators> findPacientbyOperators(String id) {
         return sessionFactory.getCurrentSession().getNamedQuery("Patientes.findPatientById").setParameter("id", Integer.parseInt(id)).list();
    }
    @Transactional
    @Override
    public List<Patientes> findPacientWithStatus(String status) {
         return sessionFactory.getCurrentSession().getNamedQuery("Patientes.findAllPatientesWithStatus").setParameter("status", Integer.parseInt(status)).setParameter("depId", getOperator().getDepartmentId()).list();
    }

    @Override
    public void changePacientStatus(Patientes patientes) {
        sessionFactory.getCurrentSession().saveOrUpdate(patientes);
    }
   
}
